package com.edu.exam.entity.assessment.generation;

import jakarta.persistence.*;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.springframework.data.annotation.CreatedDate;
import org.springframework.data.annotation.LastModifiedDate;
import org.springframework.data.jpa.domain.support.AuditingEntityListener;

import com.edu.exam.enums.assessment.generation.GenerationType;
import com.edu.exam.enums.assessment.generation.GenerationMode;
import com.edu.exam.enums.assessment.generation.GenerationStatus;
import com.edu.exam.enums.assessment.generation.ReviewResult;
import java.time.LocalDateTime;

/**
 * 任务生成记录实体类
 * 所属模块：B-05 考核计划管理模块
 * 对应数据库表：task_generation_record
 *
 * <p>任务生成过程记录实体，记录每次任务生成的详细信息、
 * 生成批次、执行结果、统计数据等。提供生成过程的完整
 * 追踪和审计功能。</p>
 *
 * @author 系统生成
 * @version 2.0
 * @since 2025-11-09
 */
@Entity
@Table(name = "task_generation_record")
@EntityListeners(AuditingEntityListener.class)
@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor
public class TaskGenerationRecord {

    /**
     * 记录ID
     */
    @Id
    @GeneratedValue(strategy = jakarta.persistence.GenerationType.IDENTITY)
    private Long id;

    /**
     * 生成批次ID
     */
    @Column(name = "generation_batch_id", nullable = false)
    private Long generationBatchId;

    /**
     * 批次编号
     */
    @Column(name = "batch_code", length = 50)
    private String batchCode;

    /**
     * 生成记录编号
     */
    @Column(name = "record_code", unique = true, length = 50, nullable = false)
    private String recordCode;

    /**
     * 生成任务名称
     */
    @Column(name = "generation_task_name", length = 200, nullable = false)
    private String generationTaskName;

    /**
     * 生成任务描述
     */
    @Column(name = "generation_task_description", length = 1000)
    private String generationTaskDescription;

    /**
     * 生成类型
     */
    @Enumerated(EnumType.STRING)
    @Column(name = "generation_type", length = 20, nullable = false)
    private GenerationType generationType;

    /**
     * 生成模式
     */
    @Enumerated(EnumType.STRING)
    @Column(name = "generation_mode", length = 20, nullable = false)
    private GenerationMode generationMode;

    /**
     * 生成状态
     */
    @Enumerated(EnumType.STRING)
    @Column(name = "generation_status", length = 20, nullable = false)
    private GenerationStatus generationStatus;

    /**
     * 生成配置ID
     */
    @Column(name = "generation_config_id")
    private Long generationConfigId;

    /**
     * 生成配置名称
     */
    @Column(name = "generation_config_name", length = 100)
    private String generationConfigName;

    /**
     * 生成规则（JSON格式）
     */
    @Column(name = "generation_rules", columnDefinition = "TEXT")
    private String generationRules;

    /**
     * 过滤条件（JSON格式）
     */
    @Column(name = "filter_criteria", columnDefinition = "TEXT")
    private String filterCriteria;

    /**
     * 生成参数（JSON格式）
     */
    @Column(name = "generation_parameters", columnDefinition = "TEXT")
    private String generationParameters;

    /**
     * 源数据范围（JSON格式）
     */
    @Column(name = "source_data_scope", columnDefinition = "TEXT")
    private String sourceDataScope;

    /**
     * 目标数据范围（JSON格式）
     */
    @Column(name = "target_data_scope", columnDefinition = "TEXT")
    private String targetDataScope;

    /**
     * 计划开始时间
     */
    @Column(name = "scheduled_start_time")
    private LocalDateTime scheduledStartTime;

    /**
     * 计划结束时间
     */
    @Column(name = "scheduled_end_time")
    private LocalDateTime scheduledEndTime;

    /**
     * 实际开始时间
     */
    @Column(name = "actual_start_time")
    private LocalDateTime actualStartTime;

    /**
     * 实际结束时间
     */
    @Column(name = "actual_end_time")
    private LocalDateTime actualEndTime;

    /**
     * 执行时长（秒）
     */
    @Column(name = "execution_duration_seconds")
    private Long executionDurationSeconds;

    /**
     * 源数据总数
     */
    @Column(name = "source_data_count")
    private Integer sourceDataCount;

    /**
     * 符合条件数据数
     */
    @Column(name = "eligible_data_count")
    private Integer eligibleDataCount;

    /**
     * 成功生成任务数
     */
    @Column(name = "successful_generations")
    private Integer successfulGenerations;

    /**
     * 失败生成数
     */
    @Column(name = "failed_generations")
    private Integer failedGenerations;

    /**
     * 跳过生成数
     */
    @Column(name = "skipped_generations")
    private Integer skippedGenerations;

    /**
     * 重复生成数
     */
    @Column(name = "duplicate_generations")
    private Integer duplicateGenerations;

    /**
     * 成功率
     */
    @Column(name = "success_rate")
    private Double successRate;

    /**
     * 完成进度
     */
    @Column(name = "completion_progress")
    private Integer completionProgress;

    /**
     * 生成结果摘要（JSON格式）
     */
    @Column(name = "generation_result_summary", columnDefinition = "TEXT")
    private String generationResultSummary;

    /**
     * 详细统计信息（JSON格式）
     */
    @Column(name = "detailed_statistics", columnDefinition = "TEXT")
    private String detailedStatistics;

    /**
     * 性能指标（JSON格式）
     */
    @Column(name = "performance_metrics", columnDefinition = "TEXT")
    private String performanceMetrics;

    /**
     * 错误统计（JSON格式）
     */
    @Column(name = "error_statistics", columnDefinition = "TEXT")
    private String errorStatistics;

    /**
     * 质量评估结果（JSON格式）
     */
    @Column(name = "quality_assessment", columnDefinition = "TEXT")
    private String qualityAssessment;

    /**
     * 生成文件路径
     */
    @Column(name = "generated_files_path", length = 500)
    private String generatedFilesPath;

    /**
     * 生成文件列表（JSON格式）
     */
    @Column(name = "generated_files_list", columnDefinition = "TEXT")
    private String generatedFilesList;

    /**
     * 备份文件路径
     */
    @Column(name = "backup_files_path", length = 500)
    private String backupFilesPath;

    /**
     * 日志文件路径
     */
    @Column(name = "log_files_path", length = 500)
    private String logFilesPath;

    /**
     * 生成优先级
     */
    @Column(name = "generation_priority")
    private Integer generationPriority;

    /**
     * 重试次数
     */
    @Column(name = "retry_count")
    private Integer retryCount;

    /**
     * 最大重试次数
     */
    @Column(name = "max_retry_count")
    private Integer maxRetryCount;

    /**
     * 超时设置（分钟）
     */
    @Column(name = "timeout_minutes")
    private Integer timeoutMinutes;

    /**
     * 是否允许部分成功
     */
    @Column(name = "allow_partial_success", nullable = false)
    private Boolean allowPartialSuccess;

    /**
     * 是否发送通知
     */
    @Column(name = "send_notification", nullable = false)
    private Boolean sendNotification;

    /**
     * 通知配置（JSON格式）
     */
    @Column(name = "notification_configuration", columnDefinition = "TEXT")
    private String notificationConfiguration;

    /**
     * 执行环境信息（JSON格式）
     */
    @Column(name = "execution_environment", columnDefinition = "TEXT")
    private String executionEnvironment;

    /**
     * 系统资源使用情况（JSON格式）
     */
    @Column(name = "system_resource_usage", columnDefinition = "TEXT")
    private String systemResourceUsage;

    /**
     * 操作人ID
     */
    @Column(name = "operator_id", nullable = false)
    private Long operatorId;

    /**
     * 操作人姓名
     */
    @Column(name = "operator_name", length = 100)
    private String operatorName;

    /**
     * 操作人角色
     */
    @Column(name = "operator_role", length = 50)
    private String operatorRole;

    /**
     * 操作人部门
     */
    @Column(name = "operator_department", length = 200)
    private String operatorDepartment;

    /**
     * 审核人ID
     */
    @Column(name = "reviewer_id")
    private Long reviewerId;

    /**
     * 审核人姓名
     */
    @Column(name = "reviewer_name", length = 100)
    private String reviewerName;

    /**
     * 审核时间
     */
    @Column(name = "review_time")
    private LocalDateTime reviewTime;

    /**
     * 审核意见
     */
    @Column(name = "review_comment", length = 1000)
    private String reviewComment;

    /**
     * 审核结果
     */
    @Enumerated(EnumType.STRING)
    @Column(name = "review_result", length = 20)
    private ReviewResult reviewResult;

    /**
     * 删除标记
     */
    @Column(name = "is_deleted", nullable = false)
    private Boolean isDeleted;

    /**
     * 创建人ID
     */
    @Column(name = "created_by", nullable = false)
    private Long createdBy;

    /**
     * 创建人姓名
     */
    @Column(name = "created_by_name", length = 100)
    private String createdByName;

    /**
     * 更新人ID
     */
    @Column(name = "updated_by")
    private Long updatedBy;

    /**
     * 更新人姓名
     */
    @Column(name = "updated_by_name", length = 100)
    private String updatedByName;

    /**
     * 创建时间
     */
    @CreatedDate
    @Column(name = "created_time", nullable = false, updatable = false)
    private LocalDateTime createdTime;

    /**
     * 更新时间
     */
    @LastModifiedDate
    @Column(name = "updated_time", nullable = false)
    private LocalDateTime updatedTime;

    /**
     * 归档时间
     */
    @Column(name = "archived_time")
    private LocalDateTime archivedTime;

    /**
     * 归档人ID
     */
    @Column(name = "archived_by")
    private Long archivedBy;

    /**
     * 归档人姓名
     */
    @Column(name = "archived_by_name", length = 100)
    private String archivedByName;

}